import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const Main = () => import('@/views/main/main');

const Recommend = () => import('@/views/main/recommend/recommend'); // 推荐

const Toplist = () => import('@/views/main/toplist/toplist'); // 排行榜

const Playlist = () => import('@/views/main/playlist/playlist'); //歌单

const Artist = () => import('@/views/main/artist/artist'); // 歌手

const NewAlbum = () => import('@/views/main/newalbum/newalbum'); // 最新音乐

const Profile = () => import('@/views/profile/profile'); // 用户相关

const MySinger = () => import('@/views/profile/MySinger') // 我的歌手

const routes = [{
  path: '',
  redirect: '/main'
}, {
  path: '/main',
  components: {
    default: Main
  },
  children: [{
    path: '',
    redirect: 'recommend',
  }, {
    /** 推荐 */
    path: 'recommend',
    component: Recommend,
    meta: {
      title: '推荐'
    }
  }, {
    /** 排行榜 */
    path: 'toplist',
    component: Toplist,
    meta: {
      title: '排行榜'
    }
  }, {
    /** 歌单 */
    path: 'playlist',
    component: Playlist,
    meta: {
      title: '歌单'
    }
  }, {
    /** 歌手 */
    path: 'artist',
    component: Artist,
    meta: {
      title: '歌手'
    }
  }, {
    /** 最新音乐 */
    path: 'newalbum',
    component: NewAlbum,
    meta: {
      title: '最新音乐'
    }
  }, {
    /** 用户相关（账户信息） */
    path: '/profile',
    component: Profile,
    meta: {
      title: '用户'
    },
    beforeEnter: (to, from, next) => {
      document.title = to.meta.title
      next()
    }
  }]
}]

const router = new VueRouter({
  routes,
  mode: "hash"
})

router.beforeEach((to, from, next) => {
  document.title = "网易云音乐"
  next();
})

export default router